/**
 * Project: apollo-base-tools
 * 
 * File Created at 2017年8月7日
 * 
 * Copyright 2015-2016 dx.com Croporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * DongXue software Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with dx.com.
 */
package org.apollo.sqlite.core;

/** 
* @ClassName: SqliteContext 
* @Description: sqlite接口
* @author wuzhenfang(wzfbj2008@163.com)
* @date 2017年8月7日 下午4:32:05 
* @version V1.0 
*/
public class SqliteContext {

	static SqlContext sqlContext;

	static SqlContext mySqlContext = new SqlContext() {

		@Override
		public String getTable(String tableName) {
			return "`" + tableName + "`";
		}

		@Override
		public String getColumn(String columnName) {
			return "`" + columnName + "`";
		}

		@Override
		public String getSqlValue(Object val) {
			if (val == null) {
				return "''";
			}
			if (val instanceof String) {
				return "'" + val + "'";
			} else {
				return String.valueOf(val);
			}
		}
	};

	public static void initContext(SqlContext context) {
		sqlContext = context;
	}

	private static SqlContext getContext() {
		if (sqlContext == null) {
			sqlContext = mySqlContext;
		}
		return mySqlContext;
	}

	public static String getTable(String tableName) {
		return getContext().getTable(tableName);
	}

	public static String getColumn(String columnName) {
		return getContext().getColumn(columnName);
	}

	public static String getSqlValue(Object val) {
		return getContext().getSqlValue(val);
	}
}
